#!/bin/bash

source @CMAKE_BINARY_DIR@/config.sh -p

# setup a trap to kill everything if the test fails/timeouts
trap 'kill -TERM $CLIENT_PID; kill -TERM $PARAMETERSERVER_PID; wait $CLIENT_PID; wait $PARAMETERSERVER_PID;' TERM

CLIENT="ex-params-client"
CLIENT+=" --id parmq-client"
CLIENT+=" --verbosity veryhigh"
CLIENT+=" --control static --color false"
CLIENT+=" --max-iterations 1"
CLIENT+=" --channel-config name=data,type=req,method=connect,address=tcp://localhost:5005,rateLogging=0"
@CMAKE_CURRENT_BINARY_DIR@/$CLIENT &
CLIENT_PID=$!

PARAMETERSERVER="parmq-server"
PARAMETERSERVER+=" --id parmq-server"
PARAMETERSERVER+=" --verbosity veryhigh"
PARAMETERSERVER+=" --control static --color false"
PARAMETERSERVER+=" --channel-name data"
PARAMETERSERVER+=" --channel-config name=data,type=rep,method=bind,rateLogging=0,address=tcp://*:5005"
PARAMETERSERVER+=" --first-input-name @CMAKE_CURRENT_BINARY_DIR@/mq_ex_params.root"
@CMAKE_BINARY_DIR@/bin/$PARAMETERSERVER &
PARAMETERSERVER_PID=$!

wait $CLIENT_PID

# stop parameter server
kill -SIGINT $PARAMETERSERVER_PID
